require('../css/index.less')
document.ready(function () {
    const baseUrl = 'http://139.9.177.51:5000';
    let imgDom = document.querySelector('.book_imgurl')
    let nameDom = document.querySelector('.book_name')
    let cateDom = document.querySelector('.book_cate')
    let descDom = document.querySelector('.book_desc')
    let mainDom = document.querySelector('.new')
    let user = JSON.parse(localStorage.getItem('user'))
    // let btn = document.getElementById('btn')
    // console.log(btn);


    // console.log(delDom);
    // 获取图书列表

    $http.get('/book/bookList', function (res) {
        // console.log(res);
        let arr = res.data
        let newHtml = ''
        // console.log(arr);

        arr.forEach(function (item, index) {
            // console.log(res);

        
            // console.log(dele);
            
            // console.log(item.id);
            newHtml += `
    
    <div class="dpflex">
     <a href="./detail.html?id=${item.id}">
        <img class="book_imgurl" src="${item.book_imgurl}">
     </a>
        <div class="flex1">
            <div class="book_name ">${item.book_name}</div>
            <div class="book_cate ">${item.book_cate}</div>
            <div class="book_desc ">${item.book_desc}</div>
        </div>
         <button data-id=${item.id}>删除</button>
    </div>
            `
            // imgDom.src = item.book_imgurl
            // nameDom.textContent = item.book_name
            // cateDom.textContent = item.book_cate
            // descDom.textContent = item.book_desc
                $http.get('/book/delete', { bookId: item.id }, function (res1) {
                    console.log(res1);
   
               })
            
        })
        mainDom.innerHTML = newHtml
        localStorage.setItem('user', JSON.stringify(res.data));



    })






})